#!/usr/bin/env bash
# utf-8
# 在node上执行

DIR=`cd $(dirname $0);pwd`
# 一定要在DP主目录中
. $DIR/PUB.sh
. $DIR/support/deploy_hadoop_env.sh

deploy_java()
{
  echo ">> deploy java"
  var_die JAVA_TAR
  mkdir -p $HOME/java
  tar -xzf tars/$JAVA_TAR -C $HOME/java
  JAVA_VERSION=`find $HOME/java -maxdepth 1 -name "jdk*"|sed "s:.*/::;1q"`
  ln -sf $JAVA_VERSION $HOME/java/jdk;

  if [ "$ANT_TAR" != "" ]; then
    tar -xzf tars/$ANT_TAR -C $HOME/java
    ANT_VERSION=`find $HOME/java -maxdepth 1 -name "apache-ant*"|sed "s:.*/::;1q"`
    ln -sf $ANT_VERSION $HOME/java/ant;
  fi

  if [ "$MAVEN_TAR" != "" ]; then
    tar -xzf tars/$MAVEN_TAR -C $HOME/java ||:;
    MAVEN_VERSION=`find $HOME/java -maxdepth 1 -name "apache-maven*"|sed "s:.*/::;1q"`
    ln -sf $MAVEN_VERSION $HOME/java/maven;
  fi
}

deploy_hadoop()
{
  echo ">> deploy hadoop"
  var_die HADOOP_TAR
  tar -xzf tars/$HADOOP_TAR -C $HOME
  ln -sf ./$HADOOP_VERSION $HADOOP_HOME
  
  if [ "$HADOOP_LZO_TAR" != "" ]; then
    tar -xzf tars/$HADOOP_LZO_TAR -C $HADOOP_HOME;
  fi
  
  if [ "$LZO_TAR" != "" ]; then
    mkdir -p $PKG_PATH;
    tar -xzf tars/$LZO_TAR -C $PKG_PATH; 
  fi
  
  if [ "$FUSE_DFS_TAR" != "" ]; then
    mkdir -p $PKG_PATH;
    tar -xzf tars/$FUSE_DFS_TAR -C $PKG_PATH;
  fi
}

main()
{
  cd $DIR
  deploy_java;
  deploy_hadoop;
  cd $OLDDIR
}

#==========
main;

